/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-28 21:00:45
 * @LastEditTime: 2022-06-28 21:37:58
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service/admin"
)

/**
 * @description: 方法描述：获取回购列表
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetRepoList(c *gin.Context) {
	var param common.RepoList

	if err := c.BindQuery(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}
	rl := admin.AdminRepoService.GetRepoList(param)
	common.ResponseListToJson(http.StatusOK, int(rl.Page), int(rl.PerPage), int(rl.Total), rl.List, c)
}

/**
 * @description: 方法描述：修改回购状态
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func ModifyRepoStatus(c *gin.Context) {
	var param common.RepoModify
	if err := c.ShouldBind(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}
	err := admin.AdminRepoService.ModifyRepoStatus(param)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}
	common.ResponseToJson(http.StatusOK, common.Ok, "success", c)
}
